package com.kerpow.KSheet;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.TextView;

public class NoteListItem extends FrameLayout {

	private OnNoteClickedHandler _OnNoteClickedHandler;
	private CharacterNote _note;
	
	public interface OnNoteClickedHandler{
		public void OnNoteLongClick(CharacterNote n);
		public void OnNoteClick(CharacterNote n);
	}
	
	public NoteListItem(Context context, CharacterNote note, OnNoteClickedHandler clickhandler) {
		super(context);
		_OnNoteClickedHandler = clickhandler;
		_note = note;
		
		LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		
		LinearLayout ll = (LinearLayout)inflater.inflate(R.layout.notelistitem, null);	
		
		TextView tv;

		tv = (TextView)ll.findViewById(R.id.notebody);
		tv.setText(note.Note);
		
		tv = (TextView)ll.findViewById(R.id.notedate);
		tv.setText(note.Modified);
		
		this.addView(ll);
		
		this.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				if(_OnNoteClickedHandler!=null)_OnNoteClickedHandler.OnNoteClick(_note);
				
			}
		});
		
		this.setOnLongClickListener(new OnLongClickListener() {
			
			@Override
			public boolean onLongClick(View v) {
				if(_OnNoteClickedHandler!=null)_OnNoteClickedHandler.OnNoteLongClick(_note);
				return true;
			}
		});
		
	}

	@Override
	public boolean onInterceptTouchEvent(MotionEvent ev) {
		return true;
		//return super.onInterceptTouchEvent(ev);
	}

}
